package com.PlantVsZombies.util;

import java.sql.SQLException;
import java.util.Date;

import javax.sql.DataSource;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.dbutils.QueryRunner;

public class DBUtil {
		private static final String url = "jdbc:mysql://127.0.0.1:3306/pvsz?useUnicode=true&characterEncoding=UTF-8";
		private static final String username = "root";
		private static final String password = "812908087";
		private static final String driverName = "com.mysql.jdbc.Driver";
		
		public 	static DataSource getDataSource(){
			BasicDataSource dataSource = null;
			try{
				dataSource = new BasicDataSource();
				dataSource.setDriverClassName(driverName);
				dataSource.setUrl(url);
				dataSource.setUsername(username);
				dataSource.setPassword(password);
			}catch(Exception f){
				System.out.println("获取数据源出错!");
			}
			return dataSource;
		}
		
		public static void main(String[] args) {
			QueryRunner queryRunner = new QueryRunner(getDataSource());
			System.out.println(queryRunner);
			/*try {
				queryRunner.update("insert into t_player(name,time) values(?,?)", new Object[]{"呵呵呵",new Date()});
			} catch (SQLException e) {
				e.printStackTrace();
			}*/
		}
}
